{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "804c2404",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu1801\":\"ZiQi\",\n",
    "    \"stu1802\":\"XiaoFeng\",\n",
    "    \"stu1803\":\"LiuYu\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59444c00",
   "metadata": {},
   "outputs": [],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9df5c1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 循环遍历一个字典\n",
    "# i是 item 在字典中打印的是什么？\n",
    "# 我想遍历整个\n",
    "for i in info:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bd56128",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 循环遍历整个字典的 items\n",
    "# 有顺序的是枚举\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7d5f5ea8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践1：将其中的key取出数字作为新的字典 stu1801 中取出数字，新的字典key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4f2c508a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1801': 'ZiQi', '1802': 'XiaoFeng', '1803': 'LiuYu'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "902e8f12",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践2： value 我也想变，所有字母大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v.upper()\n",
    "    # 可添加.改变形式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97f4a79b",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_info # 结果是字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6f92a95",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践3：让new_info key 由 ‘1801’=> 1801,在其中加int变成数值\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[int(k[3:])] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "431a9c16",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_info"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
